﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GGJ_DKG.Objects;
using GGJ_DKG.Menu;
using GGJ_DKG.Managers;
namespace GGJ_DKG.Menu
{
    class MenuScreen : Screen
    {
        Object2D bg;
        Object2D pointer;
        Object2D exitGraphic;
        bool exit;
        float multiplier = 1;

        public MenuScreen(Texture2D texture, Vector2 position) :
            base(texture, position)
        {
            this.image = texture;
        }
        public override void Load(ContentManager Content, GameWindow Window)
        {
            bg = new Object2D(image);
            bg.Position = new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2);
            pointer = new Object2D(Content.Load<Texture2D>("Menu/menu_principal_SELETOR"));
            pointer.Position = new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2); 
            exitGraphic = new Object2D(Content.Load<Texture2D>("Menu/QUIT"));
            exitGraphic.Position = new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2);

            if (!SoundManager.CheckSong("bgMusic") && Game1.Self.SoundOn)
            {
                SoundManager.StopMusic();
                SoundManager.PlayMusic("bgMusic");
            }

        }
        public override void Update(GameTime gameTime)
        {
            if (Input.GetDown(Keys.Up) && multiplier > 1)
            {
                multiplier--;
            }
            else if (Input.GetDown(Keys.Down) && multiplier < 4)
            {
                multiplier++;
            }
            else if (Input.GetDown(Keys.Enter))
            {
                switch ((int)multiplier)
                {
                    case 1:
                        Game1.Self.currentScreenSelect = Game1.Screens.LEVEL;
                        break;
                    case 2:
                        Game1.Self.currentScreenSelect = Game1.Screens.TUTORIAL;
                        break;
                    case 3:
                        Game1.Self.currentScreenSelect = Game1.Screens.CREDITS;
                        break;
                    case 4:
                        if (!exit)
                            exit = !exit;
                        else
                            exit = !exit;
                        break;
                }
            }
            else if (exit && Input.GetDown(Keys.Escape))
            {
                Game1.Self.currentScreenSelect = Game1.Screens.EXIT;
            }
          
            pointer.Position = new Vector2(Game1.Self.Window.ClientBounds.Width / 2, (float)(
                    (Game1.Self.Window.ClientBounds.Height / 2) - (pointer.Texture.Height * 1.59f)
                    + (multiplier * (float)pointer.Texture.Height)));
        }
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            bg.Draw(spriteBatch);
            pointer.Draw(spriteBatch);
            if (exit)
            {
                exitGraphic.Draw(spriteBatch);
            }
        }
    }
}